<?php 
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);

$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";

if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
    $Loaction = 'mobile/';

    if (!empty($Loaction))
    {
        ecs_header("Location: $Loaction\n");

        exit;
    }

}

$sql = "SELECT * FROM ".$ecs->table('goods')." limit 2";
// echo $sql;
// $goods = $db->getAll($sql);
$goods = $db->getAllCached($sql);

$sql = "SELECT * FROM ".$ecs->table('article');
$news = $db->getRow($sql);
// print_r($news);

// $sql = "UPDATE ".$ecs->table('article')." SET title='免责条款2' WHERE article_id=1";
// // $db->query($sql);

// $data = array(
// 		'link_name' => "wengdo",
// 		'link_url' => 'http://www.szwengdo.com',
// 		'link_logo' => '',
// 		'link_order' => 50
// 	);
// $db->autoExecute($ecs->table('friend_link'),$data,"INSERT");
// $id = $db->insert_id();
// echo $id;


// $data = array(
// 		'link_name' => "文豆网络科技有限公司"
// 	);
// $db->autoExecute($ecs->table('friend_link'),$data,"UPDATE",'link_id=4');
// echo $db->affected_rows();

// INSERT INTO ecs_keywords (keywords,count) VALUES ('xxxx',1) ON DUPLICATE KEY UPDATE count=count+1
 $insert=array('date'         => local_date('Y-m-d'),
                 'searchengine' => 'ecshop',
                 'keyword'      =>'诺基亚2',
                 'count'        => 1
                 );

$db->autoReplace($ecs->table('keywords'),$insert,array('count'=>1));


$goods = test_goods();
// print_r($goods);
print_r($GLOBALS);
function test_goods(){
	$sql = "SELECT * FROM ".$GLOBALS['ecs']->table('goods')." limit 5";
	return $GLOBALS['db']->getAll($sql);
}